package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.City;
import cn.kgc.springcloud.service.CityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 课工场
 * @date 2023/10/19
 * @description
 */
@RestController
@RequestMapping("city")
@Slf4j
public class CityController {

    @Resource
    private CityService cityService;
    @Value("${server.port}")
    private String port;

    @GetMapping
    public List<City> getList() {

        log.info("cityService port ={}",port);

        return cityService.list();
    }


    @PostMapping
    public City addCity(@RequestBody City city) {

        cityService.save(city);

        return city;
    }

    @GetMapping("{id}")
    public City getById(@PathVariable("id") Integer id) {

        return cityService.getById(id);
    }
}
